<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { debounce } from 'lodash-es'
import { queryRepairTaskByApp } from '@/api/Base/fix'

definePage({
  name: 'componentTest',
  meta: {
    level: 2,
    title: '组件测试',
  },
})

const deviceName = ref('')
const brand = ref('')
const allDevices = ref<any[]>([])
const loading = ref(false)

// Fetch all devices on mounted
onMounted(async () => {
  try {
    loading.value = true
    const res = await queryRepairTaskByApp({
      page: 1,
      pageSize: 9999,
      searchKeyword: "",
      status: 0,
      startTime: "1975-11-23", 
      endTime: "2222-07-28"
    })
    allDevices.value = res.data.list
  } finally {
    loading.value = false
  }
})

const searchDevices = debounce(() => {
  const searchText = `${deviceName.value} ${brand.value}`.trim()
  if (searchText) {
    const filtered = allDevices.value.filter(device => 
      device.deviceName.includes(deviceName.value) ||
      device.brand.includes(brand.value)
    )
    console.log('Filtered devices:', filtered)
  }
}, 300)
</script>

<template>
  <Container class="mt-[50px]">
    <van-cell-group inset>
      <van-field
        v-model="deviceName"
        label="设备名称"
        placeholder="例如：笔记本"
        @update:model-value="searchDevices"
      />
      <van-field
        v-model="brand"
        label="品牌"
        placeholder="例如：惠普"
        @update:model-value="searchDevices"
      />
    </van-cell-group>
  </Container>
</template>

<style lang="less" scoped>
.data-label {
  color: #969799;
  font-weight: 400;
  font-size: 14px;
  line-height: 16px;
  margin-top: 10px;
}

.data-content {
  height: 300px;
  padding: 20px;
  line-height: 30px;
  margin-top: 20px;
  font-size: 16px;
  border-radius: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
}
</style>
